/**
 * 
 */
package com.jie.eclipse.pan.gef.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.jie.eclipse.pan.bind.BaseDataBind;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.form.item.InputText;
import com.jie.eclipse.pan.form.support.FormItem;
import com.jie.eclipse.pan.utils.StringBuilderEx;

/**
 * @author yanjie
 *
 */
public class FieldSetDialog extends BaseDialog{
	/**
	 * @param parentShell
	 * @param data
	 */
	public FieldSetDialog(Shell parentShell, BaseDataEntity data,String action) {
		super(parentShell, data,action);
	}
	
	
	@Override
	public void initDefaultData() {
		super.initDefaultData();
	}
	
	@Override
	protected Control createDialogArea(Composite paramComposite) {
		Color bgcolor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
		Composite composite = new Composite(paramComposite, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		composite.setBackground(bgcolor);
		Label lb = null;
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("ID:");
		lb.setBackground(bgcolor);
		Text id = new Text(composite, SWT.BORDER);
		id.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("id", id);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("标题:");
		lb.setBackground(bgcolor);
		Text caption = new Text(composite, SWT.BORDER);
		caption.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("caption", caption);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("樣式:");
		lb.setBackground(bgcolor);
		Combo collapsedStyle = new Combo(composite, SWT.READ_ONLY);
		collapsedStyle.setItems(new String[]{"--","选择框","图片"});
		collapsedStyle.select(0);
		collapsedStyle.setLayoutData(new GridData(100, 24));
		collapsedStyle.setData("0","");
		collapsedStyle.setData("1","checkbox");
		collapsedStyle.setData("2","img");
		this.getDataBind().bind("collapsedStyle", collapsedStyle);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("默认展开:");
		lb.setBackground(bgcolor);
		Combo collapsed = new Combo(composite, SWT.READ_ONLY);
		collapsed.setItems(new String[]{"Y","N"});
		collapsed.select(0);
		collapsed.setLayoutData(new GridData(100, 24));
		collapsed.setData("0","true");
		collapsed.setData("1","false");
		this.getDataBind().bind("collapsed", collapsed);
		
		this.reloadRecord();
		return paramComposite;
	}
	
	@Override
	public void initRootItem(BaseDataEntity data,BaseDataBind bind,StringBuilderEx code) {
		if(bind == null)return ;
		BaseDataEntity record = bind.getRecord();
		FormItem fieldset = getNewFormItem();
		fieldset.configItem(record,"default");
		this.setRoot(fieldset);
	}
	
	@Override
	public void fillConfig(BaseDataEntity config, BaseDataBind dataBind) {
		if(config ==null || dataBind==null)return;
		BaseDataEntity record = dataBind.getRecord();
		if(!record.isNullOrEmpty("id")){
			config.spsv("id", record.gpsv("id"));
		}
		config.spsv("caption", record.gpsv("caption"));
		if(!record.isNullOrEmpty("collapsedStyle")){
			config.spsv("collapsedStyle", record.gpsv("collapsedStyle"));
		}
		
		if(!record.gpbv("collapsed", true)){
			config.spsv("collapsed","false");
		}
	}
	
	@Override
	public String getTitle() {
		return "区域框設置";
	}
}
